const express = require('express')
const app = express()

const cors = require('cors')
app.use(cors())

const path = require('path')

app.use((req, res, next) => {
    res.cc = (err, status = 1) => {
        res.send({
            status,
            msg: err instanceof Error ? err.message : err
        })
    }
    next()
})

app.use(express.urlencoded({ extended: false }))//注册解决json数据中间件


// 挂载静态资源
app.use('/images', express.static('images'))
app.use('/userimg', express.static('userimg'))

// app.use(express.static(path.join(__dirname, "/userimg")))

//首页
const mainRouter = require('./router/main')
app.use('/main', mainRouter)
//榜单
const listRouter = require('./router/list')
app.use('/list', listRouter)

//内容
const nrRouter = require('./router/nr')
app.use('/nr', nrRouter)

//评论
const pingluenRouter = require('./router/pingluen')
app.use('/pingluen', pingluenRouter)

//用户模块
const user = require('./router/user')
app.use('/user', user)

app.listen(80, () => {
    console.log('http://127.0.0.1');
})
